<?php

namespace app\index\controller;

use app\common\controller\Frontend;

class Common extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function head()
    {
        $enanme =  $this->request->param('enname');
        $client =  $this->request->param('client');
        $niutype =  $this->request->param('niutype');
        $guid = session('guid');
        if(!$guid) $this->error('错误',url('user/logout/index'));

        $userAgent = cmf_get_website_value('userAgent');
        //$domain = "http://bywidetest.ksbao.com";  //测试站
        $domain = "http://hzs.ksbao.com";  //正式站
        if($client == 'm'){
            //$url = "https://slb-user-test.ksbao.com/api/user/setLastApp?guid={$guid}&appEName={$enanme}&appVn=0";
            $url = "https://slb-user.ksbao.com/api/user/setLastApp?guid={$guid}&appEName={$enanme}&appVn=0";
            $res = $this->get_info($url);
            //$go = "http://nktest.ksbao.com/way?token=" .$guid ;
            $go = "https://nk.ksbao.com/way?token=" .$guid .'&niutype='.$niutype;
        }else{
            $go = $domain."/hzsWay?ac=".$userAgent."&token=" .$guid. "&appEName=" . $enanme . "&vn=" . 0 .'&niutype='.$niutype;
        }
        //var_dump($go);exit;
        echo("<script language='javascript'>window.top.location.href='".$go."'</script>");
    }

    //跳转设置  科目
    public function zkhead(){

        $zkurl =  urldecode($this->request->param('zkurl'));
        if(!$zkurl){
            $this->error('错误');
        }

        echo("<script language='javascript'>window.top.location.href='".$zkurl."'</script>");
        //header('location:'.$go);
    }
	
	function get_info($url){

        $ch = curl_init();
        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);

        //执行并获取HTML文档内容
        $output = curl_exec($ch);
        //释放curl句柄
        curl_close($ch);
        return $output;
    }

}
